﻿using LZ4;
using System;
using System.Text;

namespace Dotnet.Utils.Utility.EncryptUtil
{
    public static class LZ4Compressor
    {
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string CompressStringToBase64(string text)
        {
            string result = Convert.ToBase64String(LZ4Codec.Wrap(Encoding.UTF8.GetBytes(text)));
            return result;
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string DecompressStringFromBase64(string text)
        {
            var result = Encoding.UTF8.GetString(LZ4Codec.Unwrap(Convert.FromBase64String(text)));
            return result;
        }
    }
}
